using UnityEngine;

namespace UiParticles
{
    // [Assembly-CSharp.dll].UiParticles.UiParticles
    public class UiParticles : MaskableGraphic
    {
        // Fields
        private UnityEngine.ParticleSystem m_ParticleSystem;
        private UiParticles.UiParticleRenderMode m_RenderMode;
        private float m_StretchedSpeedScale;
        private float m_StretchedLenghScale;
        private bool m_IgnoreTimescale;
        private UnityEngine.ParticleSystemRenderer m_ParticleSystemRenderer;
        private UnityEngine.ParticleSystem.Particle[] m_Particles;
        
        // Properties
        public UnityEngine.ParticleSystem ParticleSystem { get; set; }
        public override UnityEngine.Texture mainTexture { get; }
        public UiParticles.UiParticleRenderMode RenderMode { get; set; }
        
        // Methods
        public UnityEngine.ParticleSystem get_ParticleSystem()
        {
            return (UnityEngine.ParticleSystem)this.m_ParticleSystem;
        }
        public void set_ParticleSystem(UnityEngine.ParticleSystem value)
        {
            if((UiParticles.SetPropertyUtility.SetClass<System.Object>(currentValue:  this.m_ParticleSystem, newValue:  value)) == false)
            {
                    return;
            }
            
            this.SetAllDirty();
        }
        public override UnityEngine.Texture get_mainTexture()
        {
            UnityEngine.Object val_7;
            var val_8;
            val_7 = this.material;
            if(val_7 != 0)
            {
                    val_7 = this.material.mainTexture;
                if(val_7 != 0)
            {
                    return this.material.mainTexture;
            }
            
            }
            
            val_8 = 536886723;
            if(mem[536886947] != 0)
            {
                    return (UnityEngine.Texture)mem[536886907] + 8;
            }
            
            val_8 = 536886723;
            return (UnityEngine.Texture)mem[536886907] + 8;
        }
        public UiParticles.UiParticleRenderMode get_RenderMode()
        {
            return (UiParticles.UiParticleRenderMode)this.m_RenderMode;
        }
        public void set_RenderMode(UiParticles.UiParticleRenderMode value)
        {
            if((UiParticles.SetPropertyUtility.SetStruct<System.Int32Enum>(currentValue:  this.m_RenderMode, newValue:  value)) == false)
            {
                    return;
            }
            
            this.SetAllDirty();
        }
        protected override void Awake()
        {
            Unknown val_2 = this.GetComponent<System.Object>();
            if(27435112 == 0)
            {
                    mem[1152921504930430424] = val_2.sharedMaterial;
            }
            
            if(val_2.renderMode == 1)
            {
                    this.RenderMode = 1;
            }
            
            this.Awake();
            this.ParticleSystem = this.GetComponent<System.Object>();
            this.m_ParticleSystemRenderer = val_2;
            throw new NullReferenceException();
        }
        public override void SetMaterialDirty()
        {
            this.SetMaterialDirty();
            if(this.m_ParticleSystemRenderer == 0)
            {
                    return;
            }
            
            this.m_ParticleSystemRenderer.sharedMaterial = 0;
        }
        protected override void OnPopulateMesh(UnityEngine.UI.VertexHelper toFill)
        {
            if(this.m_ParticleSystem == 0)
            {
                    this.OnPopulateMesh(vh:  toFill);
                return;
            }
            
            this.GenerateParticlesBillboards(vh:  toFill);
        }
        protected virtual void Update()
        {
            bool val_1 = UnityEngine.Object.op_Inequality(x:  this.m_ParticleSystem, y:  0);
            if(this.m_IgnoreTimescale == false)
            {
                goto label_2;
            }
            
            if(val_1 == false)
            {
                goto label_8;
            }
            
            this.m_ParticleSystem.Simulate(t:  UnityEngine.Time.unscaledDeltaTime, withChildren:  true, restart:  false);
            goto label_5;
            label_2:
            if((val_1 == false) || (this.m_ParticleSystem.isPlaying == false))
            {
                goto label_8;
            }
            
            label_5:
            this.SetVerticesDirty();
            label_8:
            if(this.m_ParticleSystemRenderer == 0)
            {
                    return;
            }
            
            if(this.m_ParticleSystemRenderer.enabled == false)
            {
                    return;
            }
            
            this.m_ParticleSystemRenderer.enabled = false;
        }
        private void InitParticlesBuffer()
        {
            if(this.m_Particles != null)
            {
                    UnityEngine.ParticleSystem.UnityEngine.ParticleSystem.MainModule val_1 = this.m_ParticleSystem.main;
                if(val_1.m_ParticleSystem.maxParticles <= this.m_Particles.Length)
            {
                    return;
            }
            
            }
            
            this = 27341432;
            UnityEngine.ParticleSystem.UnityEngine.ParticleSystem.MainModule val_3 = this.m_ParticleSystem.main;
            int val_4 = val_3.m_ParticleSystem.maxParticles;
            this.m_Particles = 536904521;
        }
        private void GenerateParticlesBillboards(UnityEngine.UI.VertexHelper vh)
        {
            this.InitParticlesBuffer();
            int val_1 = this.m_ParticleSystem.GetParticles(particles:  this.m_Particles);
            vh.Clear();
            if(val_1 < 1)
            {
                    return;
            }
            
            var val_3 = 0;
            label_5:
            if(val_3 >= this.m_Particles.Length)
            {
                goto label_4;
            }
            
            this.DrawParticleBillboard(particle:  new UnityEngine.ParticleSystem.UnityEngine.ParticleSystem.Particle() {m_Position = new UnityEngine.Vector3(), m_Velocity = new UnityEngine.Vector3(), m_AnimatedVelocity = new UnityEngine.Vector3(), m_InitialVelocity = new UnityEngine.Vector3(), m_AxisOfRotation = new UnityEngine.Vector3(), m_Rotation = new UnityEngine.Vector3(), m_AngularVelocity = new UnityEngine.Vector3(), m_StartSize = new UnityEngine.Vector3(), m_StartColor = new UnityEngine.Color32()}, vh:  vh);
            val_3 = val_3 + 1;
            var val_2 = 32 + 132;
            if(val_1 != val_3)
            {
                goto label_5;
            }
            
            return;
            label_4:
        }
        private void DrawParticleBillboard(UnityEngine.ParticleSystem.Particle particle, UnityEngine.UI.VertexHelper vh)
        {
            float val_30;
            float val_31;
            float val_32;
            float val_33;
            float val_34;
            float val_35;
            float val_36;
            float val_37;
            float val_38;
            UnityEngine.Vector3 val_1 = particle.m_Position.x.position;
            val_30 = val_1.y;
            val_31 = val_1.z;
            UnityEngine.Vector3 val_2 = particle.m_Position.x.rotation3D;
            val_32 = val_2.x * 0.01745329f;
            val_33 = val_2.y * 0.01745329f;
            val_34 = val_2.z * 0.01745329f;
            UnityEngine.Quaternion val_3 = UnityEngine.Quaternion.Internal_FromEulerRad(euler:  new UnityEngine.Vector3() {x = val_32, y = val_33, z = val_34});
            val_35 = val_3.x;
            val_36 = val_3.y;
            val_37 = val_3.z;
            val_38 = val_3.w;
            UnityEngine.ParticleSystem.UnityEngine.ParticleSystem.MainModule val_4 = this.m_ParticleSystem.main;
            if(val_4.m_ParticleSystem.simulationSpace == 1)
            {
                    val_32 = val_1.x;
                val_33 = val_30;
                val_34 = val_31;
                UnityEngine.Vector3 val_7 = this.rectTransform.InverseTransformPoint(position:  new UnityEngine.Vector3() {x = val_32, y = val_33, z = val_34});
                val_30 = val_7.y;
                val_31 = val_7.z;
            }
            
            float val_10 = particle.m_Position.x.startLifetime - particle.m_Position.x.remainingLifetime;
            float val_30 = particle.m_Position.x.startLifetime;
            UnityEngine.Vector3 val_12 = particle.m_Position.x.GetCurrentSize3D(system:  this.m_ParticleSystem);
            if(this.m_RenderMode == 1)
            {
                    val_30 = val_10 / val_30;
                this.GetStrechedBillboardsSizeAndRotation(particle:  new UnityEngine.ParticleSystem.UnityEngine.ParticleSystem.Particle() {m_Position = new UnityEngine.Vector3(), m_Velocity = new UnityEngine.Vector3(), m_AnimatedVelocity = new UnityEngine.Vector3(), m_InitialVelocity = new UnityEngine.Vector3(), m_AxisOfRotation = new UnityEngine.Vector3(), m_Rotation = new UnityEngine.Vector3(), m_AngularVelocity = new UnityEngine.Vector3(), m_StartSize = new UnityEngine.Vector3(), m_StartColor = new UnityEngine.Color32()}, timeAlive01:  val_30, size3D:  new UnityEngine.Vector3() {x = val_12.y, y = val_12.z, z = val_3.w}, rotation:  new UnityEngine.Quaternion());
                val_33 = val_12.y;
                val_32 = val_12.x;
                val_36 = val_3.y;
                val_35 = val_3.x;
                val_38 = val_3.w;
                val_37 = val_3.z;
            }
            
            float val_13 = val_32 * (-0.5f);
            float val_14 = val_33 * 0.5f;
            float val_15 = val_32 * 0.5f;
            float val_16 = val_33 * (-0.5f);
            UnityEngine.Vector3 val_17 = UnityEngine.Quaternion.op_Multiply(rotation:  new UnityEngine.Quaternion() {x = val_35, y = val_36, z = val_37, w = val_38}, point:  new UnityEngine.Vector3() {x = val_13, y = val_14, z = 0f});
            UnityEngine.Vector3 val_18 = UnityEngine.Quaternion.op_Multiply(rotation:  new UnityEngine.Quaternion() {x = val_35, y = val_36, z = val_37, w = val_38}, point:  new UnityEngine.Vector3() {x = val_15, y = val_14, z = 0f});
            UnityEngine.Vector3 val_19 = UnityEngine.Quaternion.op_Multiply(rotation:  new UnityEngine.Quaternion() {x = val_35, y = val_36, z = val_37, w = val_38}, point:  new UnityEngine.Vector3() {x = val_15, y = val_16, z = 0f});
            UnityEngine.Vector3 val_20 = UnityEngine.Quaternion.op_Multiply(rotation:  new UnityEngine.Quaternion() {x = val_35, y = val_36, z = val_37, w = val_38}, point:  new UnityEngine.Vector3() {x = val_13, y = val_16, z = 0f});
            UnityEngine.Color32 val_21 = particle.m_Position.x.GetCurrentColor(system:  this.m_ParticleSystem);
            int val_22 = vh.currentVertCount;
            UnityEngine.ParticleSystem.UnityEngine.ParticleSystem.TextureSheetAnimationModule val_23 = this.m_ParticleSystem.textureSheetAnimation;
            bool val_24 = val_23.m_ParticleSystem.enabled;
            if(val_24 == false)
            {
                goto label_8;
            }
            
            this.EvaluateTexturesheetUVs(particle:  new UnityEngine.ParticleSystem.UnityEngine.ParticleSystem.Particle() {m_Position = new UnityEngine.Vector3(), m_Velocity = new UnityEngine.Vector3(), m_AnimatedVelocity = new UnityEngine.Vector3(), m_InitialVelocity = new UnityEngine.Vector3(), m_AxisOfRotation = new UnityEngine.Vector3(), m_Rotation = new UnityEngine.Vector3(), m_AngularVelocity = new UnityEngine.Vector3(), m_StartSize = new UnityEngine.Vector3(), m_StartColor = new UnityEngine.Color32()}, timeAlive:  val_10, uvs:  536881643);
            if(536881643 != 0)
            {
                goto label_9;
            }
            
            label_8:
            val_24.EvaluateQuadUVs(uvs:  536881643);
            label_9:
            if(mem[536881667] != 0)
            {
                    byte val_25 = val_21.r & 4294967295;
                val_20.x = val_1.x + val_20.x;
                val_20.y = val_30 + val_20.y;
                val_20.z = val_31 + val_20.z;
                vh.AddVert(position:  new UnityEngine.Vector3() {x = val_20.x, y = val_20.y, z = val_20.z}, color:  new UnityEngine.Color32() {r = val_25, g = val_25, b = val_25, a = val_25}, uv0:  new UnityEngine.Vector4() {x = mem[536881675], y = mem[536881679], z = 0f, w = 0f});
                if(mem[536881667] > 1)
            {
                    float val_32 = val_17.y;
                float val_31 = val_17.x;
                float val_33 = val_17.z;
                val_31 = val_1.x + val_31;
                val_32 = val_30 + val_32;
                val_33 = val_31 + val_33;
                vh.AddVert(position:  new UnityEngine.Vector3() {x = val_31, y = val_32, z = val_33}, color:  new UnityEngine.Color32() {r = val_25, g = val_25, b = val_25, a = val_25}, uv0:  new UnityEngine.Vector4() {x = mem[536881683], y = mem[536881687], z = 0f, w = 0f});
                if(mem[536881667] > 2)
            {
                    float val_35 = val_18.y;
                float val_34 = val_18.x;
                float val_36 = val_18.z;
                val_34 = val_1.x + val_34;
                val_35 = val_30 + val_35;
                val_36 = val_31 + val_36;
                vh.AddVert(position:  new UnityEngine.Vector3() {x = val_34, y = val_35, z = val_36}, color:  new UnityEngine.Color32() {r = val_25, g = val_25, b = val_25, a = val_25}, uv0:  new UnityEngine.Vector4() {x = mem[536881691], y = mem[536881695], z = 0f, w = 0f});
                if(mem[536881667] > 3)
            {
                    float val_38 = val_19.z;
                float val_37 = val_19.y;
                val_37 = val_30 + val_37;
                val_38 = val_31 + val_38;
                vh.AddVert(position:  new UnityEngine.Vector3() {x = val_1.x + val_19.x, y = val_37, z = val_38}, color:  new UnityEngine.Color32() {r = val_25, g = val_25, b = val_25, a = val_25}, uv0:  new UnityEngine.Vector4() {x = mem[536881699], y = mem[536881703], z = 0f, w = 0f});
                int val_27 = val_22 + 2;
                vh.AddTriangle(idx0:  val_22, idx1:  val_22 + 1, idx2:  val_27);
                vh.AddTriangle(idx0:  val_27, idx1:  val_22 + 3, idx2:  val_22);
                return;
            }
            
            }
            
            }
            
            }
        
        }
        private void EvaluateQuadUVs(UnityEngine.Vector2[] uvs)
        {
            if(uvs.Length == 0)
            {
                    throw new NullReferenceException();
            }
            
            uvs[0] = 0;
            if(uvs.Length == 1)
            {
                    throw new NullReferenceException();
            }
            
            uvs[1] = 0.0078125;
            if(uvs.Length <= 2)
            {
                    throw new NullReferenceException();
            }
            
            uvs[2] = 1;
            if(uvs.Length == 3)
            {
                    throw new NullReferenceException();
            }
            
            uvs[3] = 5.26354424712089E-315;
        }
        private void EvaluateTexturesheetUVs(UnityEngine.ParticleSystem.Particle particle, float timeAlive, UnityEngine.Vector2[] uvs)
        {
            var val_7;
            float val_32;
            float val_33;
            var val_34;
            float val_33 = timeAlive;
            UnityEngine.ParticleSystem.UnityEngine.ParticleSystem.TextureSheetAnimationModule val_1 = this.m_ParticleSystem.textureSheetAnimation;
            float val_32 = particle.m_Position.x.startLifetime;
            val_32 = val_32 / (float)val_1.m_ParticleSystem.cycleCount;
            val_33 = val_33 / val_32;
            UnityEngine.ParticleSystem.UnityEngine.ParticleSystem.MinMaxCurve val_6 = val_1.m_ParticleSystem.frameOverTime;
            val_32 = val_7.Evaluate(time:  val_33);
            UnityEngine.ParticleSystemAnimationType val_10 = val_1.m_ParticleSystem.animation;
            if(val_10 == 1)
            {
                goto label_1;
            }
            
            val_33 = 0f;
            if(val_10 != 0)
            {
                goto label_4;
            }
            
            int val_11 = val_1.m_ParticleSystem.numTilesX * val_1.m_ParticleSystem.numTilesY;
            float val_34 = (float)val_11;
            val_34 = val_32 * val_34;
            if(val_34 < 0)
            {
                goto label_4;
            }
            
            val_11 = val_11 - 1;
            var val_12 = (val_34 > (float)val_11) ? ((float)val_11) : (val_34);
            goto label_4;
            label_1:
            float val_35 = (float)val_1.m_ParticleSystem.numTilesX;
            val_35 = val_32 * val_35;
            val_32 = (val_32 >= 0) ? ((val_32 > ((float)val_1.m_ParticleSystem.numTilesX - 1)) ? ((float)val_1.m_ParticleSystem.numTilesX - 1) : (val_32)) : 0f;
            val_34 = val_1.m_ParticleSystem.rowIndex;
            if(val_1.m_ParticleSystem.useRandomRow != false)
            {
                    UnityEngine.Random.InitState(seed:  particle.m_Position.x.randomSeed);
                val_34 = UnityEngine.Random.Range(minInclusive:  0, maxExclusive:  val_1.m_ParticleSystem.numTilesY);
            }
            
            val_33 = val_32 + ((float)val_1.m_ParticleSystem.numTilesX * val_34);
            label_4:
            int val_24 = val_1.m_ParticleSystem.numTilesX;
            int val_36 = (int)val_33;
            var val_25 = (val_33 == Infinityf) ? -2147483648 : (val_36);
            if(uvs.Length == 0)
            {
                    throw new NullReferenceException();
            }
            
            val_36 = val_25 / val_24;
            float val_39 = 1f;
            val_36 = val_25 - (val_36 * val_24);
            var val_37 = ~(val_25 / val_1.m_ParticleSystem.numTilesX);
            float val_38 = (float)val_1.m_ParticleSystem.numTilesY;
            float val_31 = val_39 / (float)val_1.m_ParticleSystem.numTilesX;
            val_37 = val_1.m_ParticleSystem.numTilesY + val_37;
            val_38 = val_39 / val_38;
            val_39 = val_31 * (float)val_36;
            float val_40 = (float)val_37;
            val_40 = val_38 * val_40;
            uvs[0] = val_39;
            uvs[0] = val_40;
            if(uvs.Length == 1)
            {
                    throw new NullReferenceException();
            }
            
            val_38 = val_38 + val_40;
            uvs[1] = val_39;
            uvs[1] = val_38;
            if(uvs.Length <= 2)
            {
                    throw new NullReferenceException();
            }
            
            val_31 = val_31 + val_39;
            uvs[2] = val_31;
            uvs[2] = val_38;
            if(uvs.Length == 3)
            {
                    throw new NullReferenceException();
            }
            
            uvs[3] = val_31;
            uvs[3] = val_40;
        }
        private void GetStrechedBillboardsSizeAndRotation(UnityEngine.ParticleSystem.Particle particle, float timeAlive01, UnityEngine.Vector3 size3D, [Out] UnityEngine.Quaternion rotation)
        {
            var val_5;
            float val_30;
            float val_31;
            float val_32;
            float val_33;
            float val_34;
            float val_35;
            val_30 = 0;
            val_32 = mem[mem[536895737]];
            val_32 = mem[536895737];
            val_31 = mem[mem[536895737] + 4];
            val_31 = mem[536895737] + 4;
            val_33 = mem[mem[536895737] + 8];
            val_33 = mem[536895737] + 8;
            UnityEngine.ParticleSystem.UnityEngine.ParticleSystem.VelocityOverLifetimeModule val_1 = this.m_ParticleSystem.velocityOverLifetime;
            if(val_1.m_ParticleSystem.enabled != false)
            {
                    UnityEngine.ParticleSystem.UnityEngine.ParticleSystem.VelocityOverLifetimeModule val_3 = this.m_ParticleSystem.velocityOverLifetime;
                UnityEngine.ParticleSystem.UnityEngine.ParticleSystem.MinMaxCurve val_4 = val_3.m_ParticleSystem.x;
                val_32 = val_5.Evaluate(time:  timeAlive01);
                UnityEngine.ParticleSystem.UnityEngine.ParticleSystem.VelocityOverLifetimeModule val_8 = this.m_ParticleSystem.velocityOverLifetime;
                UnityEngine.ParticleSystem.UnityEngine.ParticleSystem.MinMaxCurve val_9 = val_8.m_ParticleSystem.y;
                val_31 = val_5.Evaluate(time:  timeAlive01);
                UnityEngine.ParticleSystem.UnityEngine.ParticleSystem.VelocityOverLifetimeModule val_11 = this.m_ParticleSystem.velocityOverLifetime;
                UnityEngine.ParticleSystem.UnityEngine.ParticleSystem.MinMaxCurve val_12 = val_11.m_ParticleSystem.z;
                val_30 = timeAlive01;
                val_33 = val_5.Evaluate(time:  val_30);
            }
            
            UnityEngine.Vector3 val_14 = particle.m_Position.x.velocity;
            float val_29 = val_14.y;
            val_32 = val_32 + val_14.x;
            val_29 = val_31 + val_29;
            float val_15 = val_33 + val_14.z;
            val_34 = mem[mem[536895737] + 32];
            val_34 = mem[536895737] + 32;
            val_34 = val_34;
            val_14.x = val_32 * val_32;
            val_14.y = val_29 * val_29;
            val_14.x = val_14.x + val_14.y;
            float val_18 = (mem[536895737] + 24) * (mem[536895737] + 24);
            val_18 = val_18 + ((mem[536895737] + 24 + 4) * (mem[536895737] + 24 + 4));
            if(mem[536889581] == 0)
            {
                    val_34 = val_34;
            }
            
            val_18 = ((val_15 * val_15) + val_14.x) * ((val_34 * val_34) + val_18);
            val_35 = 0f;
            if(val_18 >= 0)
            {
                    float val_22 = val_32 * (mem[536895737] + 24);
                val_22 = val_22 + (val_29 * (mem[536895737] + 24 + 4));
                val_22 = (val_15 * val_34) + val_22;
                val_18 = val_22 / val_18;
                val_15 = (val_18 >= 0) ? (val_22) : -1f;
                val_35 = (float)(double)val_15 * 57.29578f;
            }
            
            float val_25 = (val_32 < 0) ? 1f : -1f;
            val_35 = val_25 * val_35;
            val_25 = val_35 * 0.01745329f;
            UnityEngine.Quaternion val_26 = UnityEngine.Quaternion.Internal_FromEulerRad(euler:  new UnityEngine.Vector3() {x = 0f, y = 0f, z = val_25});
            mem2[0] = val_26.x;
            mem2[0] = val_26.y;
            mem2[0] = val_26.z;
            mem2[0] = val_26.w;
            float val_30 = X2 + 4;
            float val_27 = val_30 * this.m_StretchedLenghScale;
            mem2[0] = val_27;
            float val_31 = 0f;
            val_30 = val_30 * this.m_StretchedSpeedScale;
            val_31 = (X2 + 8) + val_31;
            val_30 = val_27 + val_30;
            mem2[0] = X2 + val_31;
            mem2[0] = val_30;
            mem2[0] = val_31;
        }
        public UiParticles()
        {
            this.m_StretchedSpeedScale = 1;
        }
    
    }

}
